﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>企业管理</title>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
<link rel="stylesheet" href="./css/backstage.css" media="all">
<script src="js/line.js"></script>
<script src="./js/jquery.min.js"></script>
<link rel="stylesheet" href="./js/layui/css/layui.css"></link>
<script src="./js/layui/layui.all.js"></script>

  <script>
     //日期控件
	  $(function(){
		   layui.use('laydate', function(){
			 var laydate = layui.laydate;
			 laydate.render({elem: '#searchbegin'});
			 laydate.render({elem: '#searchend'});
			 laydate.render({elem: '#vipbegin'});
			 laydate.render({elem: '#vipend'});
		  }); 
	  });
  


	$(function() {
		search();
	});

	function search() {
		var comName = $("#comName").val();
		var management = $("#management").val();
		var searchbegin = $("#searchbegin").val();
		var searchend = $("#searchend").val();
		var pageIndex = 1; //当前是第几页,默认是第一页       	
		renderData(pageIndex, comName, management, searchbegin, searchend);
	}

	function renderData(pageIndex, comName, management, searchbegin, searchend) {
		$("tbody").empty();
				$.ajax({
					url : "../admin/normalCompanyList",
					data : {
						comName : comName,
						management : management,
						searchbegin : searchbegin,
						searchend : searchend,
						page : pageIndex,
						limit : 15
					},
					dataType : "json",
					async : false,
					success : function(result) {
						var compList = result.obj.list;
						for (var i = 0; i < compList.length; i++) {
							var v = compList[i];

							var tr="";
	        	        	tr+="<tr>";
	        	        	tr +="<td >" + v.registerTime + "</td>";
	        	        	tr+="<td><a title='"+v.comName+"'  href='generalInformation.html?comid="+v.comid+"'> "+v.shortComName+"</a></td>";
	        	        	tr+="<td ><span class='demo'>"+"<a style='text-decoration:none;color:black' title='"+v.management+"'>"+ v.shortManagement+"</a>"+"</span></td>" ;
	        	        	tr+="<td class='td-manage'>";
	        	        	tr+="<a class='mlbtn' href='javascript:void(0)' onclick=update("+v.comid+")>修改</a>";
	        	        	tr+="<a class='mlbtn' href='javascript:void(0)' onclick=showDIV("+v.comid+")>升级为vip</a>";
	        	        	tr+="<a class='mlbtn' href='javascript:void(0)' onclick=del("+v.comid+")>删除</a>";  
	        	        	tr+="</td>";
	        	        	tr+="</tr>";

	        	        	$("#tbody").append(tr);	
	        	        	
						}

						pageFun(result.obj, comName, management, searchbegin,searchend);
							
					}
				});
	}

	function update(comid) {
		window.location.href = "updateOrdinary.html?comid=" + comid;
	}

	function del(comid) {
		if (confirm("确定要删除吗?") == true) {
			$.ajax({
				url : "../admin/deleteNormalCompany",
				data : {
					comid : comid
				},
				success : function(data) {
					alert("删除成功!");
					search();
				}
			});
		}
	}

	function showDIV(comid) {
		layui.use("layer", function() {
			var layer = layui.layer;

			layer.open({
				type : 1,
				title : "请输入vip起止期日期",
				content : $('#div_vipdate'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
				btn : [ '确定' ],
				yes : function(index, layero) {

					//验证
					var vipbegin = $("#vipbegin").val();
					var vipend = $("#vipend").val();

					var str = "";
					if (vipbegin == "") {
						str += "vip起始时间不能为空\r\n";
					}
					if (vipend == "") {
						str += "vip结束时间不能为空\r\n"
					}
					if (vipend < vipbegin) {
						str += "vip结束时间不能早于起始时间\r\n"
					}

					if (str != "") {
						alert(str);
					}
					else{
						$.ajax({
							url : "../admin/upgradetovip",
							type : "post",
							offset: 'auto',
						//  offset: ['100px', '50px'],
							data : {
								comid : comid,
								vipbegin : $("#vipbegin").val(),
								vipend : $("#vipend").val()
							},
							success : function(data) {
								search();
								alert(data.message);
								//关闭小窗口
								$("#comid").val("");
								$("#vipbegin").val("");
								$("#vipend").val("");
								$(".layui-layer-close1").trigger('click');
							}
						});

					}
				}
			});

		});

	}

</script>

<script>
	//分页函数
	function pageFun(data, comName, management, searchbegin, searchend) {
		pageinfo = "";
		//总页数
		pagenums = parseInt(data.pages);
		//当前页
		pagecurrent = parseInt(data.pageNum);
		//可视页数
		showpages = 15;

		if (pagecurrent > 1) {
			pageinfo += "<li><a href='javascript:void(0);' onclick=\"renderData("
					+ (pagecurrent - 1)
					+ ",'"
					+ comName
					+ "','"
					+ management
					+ "','"
					+ searchbegin
					+ "','"
					+ searchend
					+ "')\"> < </a></li>";
		} else {
			pageinfo += "<li><a href='javascript:void(0);'> < </a></li>";
		}
		for_begin = 1;
		for_judge = 1;
		pageinf_begin = "";
		pageinf_end = "";
		if (pagenums > 0) {
			if (pagenums <= showpages) {
				for_begin = 1;
				for_judge = pagenums;
				pageinf_begin = "";
				pageinf_end = "";
			} else if (pagenums > showpages && pagecurrent == 1) {
				for_begin = 1;
				for_judge = showpages;
				pageinf_begin = "";
				pageinf_end = "<li><a>...</a></li>";
			} else if (pagenums <= (pagecurrent + showpages) && pagecurrent > 1) {
				for_begin = pagecurrent;
				for_judge = pagenums;
				pageinf_begin = "<li><a>...</a></li>";
				pageinf_end = "";
			} else if (pagenums > (pagecurrent + showpages) && pagecurrent > 1) {
				for_begin = pagecurrent;
				for_judge = pagecurrent + showpages - 1;
				pageinf_begin = "<li><a>...</a></li>";
				pageinf_end = "<li><a>...</a></li>";
			}

			pageinfo += pageinf_begin;
			for (i = for_begin; i <= for_judge; i++) {
				if (i == pagecurrent) {
					pageinfo += "<li  class='active'><a href='javascript:void(0);' onclick=\"renderData("
							+ i
							+ ",'"
							+ comName
							+ "','"
							+ management
							+ "','"
							+ searchbegin
							+ "','"
							+ searchend
							+ "')\">"
							+ i
							+ "</a></li>";
				} else {
					pageinfo += "<li><a href='javascript:void(0);' onclick=\"renderData("
							+ i
							+ ",'"
							+ comName
							+ "','"
							+ management
							+ "','"
							+ searchbegin
							+ "','"
							+ searchend
							+ "')\">"
							+ i
							+ "</a></li>";
				}
			}
			pageinfo += pageinf_end;

			if (pagecurrent < pagenums) {
				pageinfo += "<li><a href=\"javascript:renderData("
						+ (pagecurrent + 1) + ",'" + comName + "','"
						+ management + "','" + searchbegin + "','" + searchend
						+ "')\"> > </a></li>";
			} else {
				pageinfo += "<li><a href='javascript:void(0);'> > </a></li>";
			}
			$(".pagelist ul").empty();
			$(".pagelist ul").append(pageinfo);
		}
	}
</script>
</head>
<body>
	<!-- 把企业改为vip的时候弾出一个输入日期的框 , 美工要调整一下它的样式-->
	<div id="div_vipdate" style="display: none;margin:30px;" >
		    <input id="comid" type="hidden"> 
	       从 :  <input   id="vipbegin" placeholder="vip开始日期"> <br />  <br />
	       到 :  <input   id="vipend" placeholder="vip截止日期">
	</div>


	<div class="wrap">
		<div class="x-nav">
			<div class="title">
				<a><cite>普通企业管理</cite></a>
			</div>
		</div>
		<div class="form">
			<p>
				<span>检索区:</span>
			</p>
			<p>
				<span>按企业名称</span> <input type="text" id="comName" />
			</p>
			<p>
				<span>按主营项目</span> <input type="text" id="management" />
			</p>
			<p>
				<span>按入驻日期</span> <input   id="searchbegin"
					placeholder="开始日期" />
			</p>
			<p>
				<span>到</span> <input   id="searchend" placeholder="截止日期" />
			</p>
			<p>
				<button class="btn2" onclick="search()">
					<i class="layui-icon">&#xe615;</i> 搜索
				</button>
			</p>
		</div>

		<div class="x-body">
			<table class="layui-table" id="table">
				<thead>
					<tr>
						<th>入驻日期</th>
						<th>企业全称</th>
						<th>主营项目</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="tbody">

				</tbody>
			</table>


			<div class="pagelist">
				<ul class="nav">
				</ul>
			</div>
		</div>
	</div>

</body>
</html>